package com_5;

import java.util.ArrayList;
import java.util.function.Predicate;

public class predicateDemo1 {//
    public static void main(String[] args) {//
        String[] arr = {"诸葛亮,45", "曹操,46", "周瑜,25"};//定义一个数组
        ArrayList<String> list = getList(arr, s -> s.split(",")[0].length() > 2,
                //
                s -> Integer.parseInt(s.split(",")[1]) > 26);//
        for (String s : list) {//
            System.out.println(s);//
        }
        ArrayList<String> list1 = getList(arr, new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return s.split(",")[0].length() > 1;
            }
        }, new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return (Integer.parseInt(s.split(",")[1])) > 25;
            }
        })
                ;
        for (String s : list1) {//
            System.out.println(s);//
        }

    }

    public  static ArrayList<String>  getList(String[] arr, Predicate<String> pre1,Predicate<String>pre2){
        //
        ArrayList<String> list=new ArrayList<>();//
        for (String s : arr) {//
            if(pre1.and(pre2).test(s)){//
                list.add(s);//
            }
        }
        return list;//
    }
}
